package cn.lupin.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.*;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("unchecked")
public class HttpUtils {

    private static final OkHttpClient CLIENT = new OkHttpClient();

    public static Map<String,String> doHttpGetWx(String url) {
        Request request = new Request.Builder()
                .url(url)
                .build();
        try (Response response = CLIENT.newCall(request).execute()) {
            if (response.isSuccessful()) {
                if(response.body() != null){
                    String responseBody = response.body().string();
                    ObjectMapper mapper = new ObjectMapper();
                    HashMap<String,String> result =mapper.readValue(responseBody, HashMap.class);
                    System.out.println(result);
                    return result;
                }
            }
            return null;
        } catch (Exception e) {
            System.out.println(e.toString());
            return null;
        }
    }
}
